package com.quanyue.haircut.system.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Principal;
import com.quanyue.haircut.domain.entity.FsConfig;
import com.quanyue.haircut.system.service.FsConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文件服务器设置")
@RestController
@RequestMapping(value = "/api/fs")
public class FsConfigController {

    @Autowired
    private FsConfigService configService;

    @ApiOperation("获取设置")
    @GetMapping(value = "/config", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<FsConfig> config(Principal principal) {
        return ServiceResult.success(configService.findByMerchant(principal.getMerchantNo()));
    }

    @ApiOperation("更新设置")
    @PutMapping(value = "/config", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> config(@RequestBody FsConfig config, Principal principal) {
        config.setMerchantNo(principal.getMerchantNo());
        configService.update(config);
        return ServiceResult.SUCCESS;
    }
}
